import { _decorator, Component, Node } from 'cc';
import { Dictionary } from '../utils/Dictionary';
import { roleEquipEnum } from '../Enum';
import { StartSceneGameMgr } from './StartSceneGameMgr';
import { Equip } from './Equip';
import { keepOneDecimalFull2 } from '../utils/utils';
import { UserInfo } from './UserInfo';
import { loading } from '../loading';
const { ccclass, property } = _decorator;

@ccclass('Role')
export class Role {
   
    roleId;
    roleType;
    roleTp:any;
 
    initData(data) {
        this.roleId = data.roleId;
        this.roleType = data.roleType;
        this.roleTp = UserInfo.roleCongfiDic.get(this.roleType);

    }

    //得到自己的装备字典
    getSelfAllEquipDic() {
        let dic: Dictionary<number, Equip> = new Dictionary();
        UserInfo.hasEquipDic.getValueList().forEach((ele) => {
            if (ele.ownerRoleId == this.roleId) {
                dic.set(ele.equipId,ele);
            }
        })
        
        return dic;
    }

    //得到自己指定装备类型的装备
    getSelfEquipByEquipClass(_equipClass) {
        let resEquip=null;
        this.getSelfAllEquipDic().getValueList().forEach((ele) => {
            if (ele.equipTp.equipClass==_equipClass) {
                resEquip=ele;
            }
        })
        return resEquip
    }

    get roleAttackAttribute() {
        let res=this.roleTp.attack;
        this.getSelfAllEquipDic().getValueList().forEach(element => {
            res+=element.attackAddition;
        });
        let goBattlePet=StartSceneGameMgr.ins.getGoBattlePet();
        if (goBattlePet) {
        res+=goBattlePet.attackAddition;
        }
    
        return res
    }
    get roleFrequencyAttribute() {//返回几秒发射一次
        let res = this.roleTp.frequency;
        this.getSelfAllEquipDic().getValueList().forEach(element => {
            res += element.frequencyAddition;
        });
        let goBattlePet = StartSceneGameMgr.ins.getGoBattlePet();
        if (goBattlePet) {
            res += goBattlePet.frequencyAddition;
        }
        if (res < 0.2) {//限制最低0.2秒频率
            res = 0.2
        }
        return res

    }
    get roleCriticalHitAttribute() {//返回暴击率，小数
        let res=this.roleTp.criticalHit;
        this.getSelfAllEquipDic().getValueList().forEach(element => {
            res+=element.criticalHitAddition;
        });
        let goBattlePet = StartSceneGameMgr.ins.getGoBattlePet();
        if (goBattlePet) {
            res += goBattlePet.criticalHitAddition;
        }

        if (res>0.9) {//限制最高90%
            res=0.9
        }
        return res
    }
    get battleValue() {
        let res;
        res = ((this.roleAttackAttribute/10+this.roleCriticalHitAttribute)+(5-this.roleFrequencyAttribute))*100;

        let goBattlePet=StartSceneGameMgr.ins.getGoBattlePet();
        if (goBattlePet) {
            res+=goBattlePet.battleValue;
        }
        return res
    }

    //得到的分解奖励
    get salvageGet() {
        let res;
        res = (this.roleTp.quality+1)*80
        return res;
    }

}


